﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SouthApps.MobileHealth.SDK.DAL.Model;

namespace SouthApps.MobileHealth.SDK.Utils
{
    public static class DistanceCalculator
    {
        public static double GetDistance(Location sourceLocation, Location destinationLocation)
        {
            double distance =  (3956 * 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin((sourceLocation.Latitude - destinationLocation.Latitude) * Math.PI/180 / 2), 2) +
                   Math.Cos(sourceLocation.Latitude * Math.PI/180) * Math.Cos(sourceLocation.Latitude * Math.PI/180) *
                     Math.Pow(Math.Sin((sourceLocation.Longitude - destinationLocation.Longitude) * Math.PI/180 / 2), 2))))*1.609344;

            return distance;
        }
    }
}
